-
Notifications
You must be signed in to change notification settings - Fork 174
ДЗ Dagger 2 #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
ДЗ Dagger 2 #160
Conversation
Это корень нашего дерева компонентов. Инициализируется в классе App, прокидывает в граф через Component Dependencies/Subcomponents ниже по графу следующие сущности: Context(Application) до ProducerFragmentComponent и ReceiverFragmentComponent. Проброс Context в граф реализуйте через BindsInstance + ComponentFactory
…Homework # Conflicts: # app/src/main/AndroidManifest.xml # app/src/main/java/ru/otus/daggerhomework/App.kt
Коммуникацию между Producer и Receiver осуществите через канал/StateFlow/Subject либо другую реализацию обсервера которая уже есть в графе. ProducerViewModel должна отправлять ивенты, ReceiverViewModel должна получать эвенты. Обсерверы должны прокидываться в конструкторы вьюмоделей и существовать в единственном экземпляре в Activity.
| @@ -0,0 +1,9 @@ | |||
| package ru.otus.daggerhomework | |||
|
|
|||
| import java.util.UUID | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется лишний импорт тут
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
| fun build(@BindsInstance context: Context): ApplicationComponent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь лучше добавить квалифайер для контекста и написать типо @ApplicationContext чтобы потом различать с контекстом активити.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И добавить метод getContext() чтобы научить ApplicationComponent отдавать его наружу
| interface MainActivityComponent { | ||
| @Component.Factory | ||
| interface Factory { | ||
| fun build(@BindsInstance activity: Activity): MainActivityComponent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А вот здесь добавить контекст от активити c квалифайером @ActivityContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И добавить метод getContext() чтобы научить MainActivityComponent отдавать его наружу
| interface Factory { | ||
| fun build( | ||
| mainActivityComponent: MainActivityComponent, | ||
| @BindsInstance context: Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И здесь уже не добавлять контекст, потому что MainActivityComponent должен его предоставлять итак.
| interface Factory { | ||
| fun build( | ||
| mainActivityComponent: MainActivityComponent, | ||
| @BindsInstance context: Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь тоже самое. Контекст уже не нужно передавать. Если вы все передали через апп и активити компоненты.
* Отрефакторены компоненты
ДЗ Dagger 2